package com.intellij.licensecommon.f.impl;

import com.intellij.licensecommon.data.LicenseImpl;
import com.intellij.licensecommon.message.Message;
import com.intellij.licensecommon.message.impl.TaggedMessage;
import com.intellij.licensecommon.message.impl.b;
import org.jdom.Element;

class f extends Constants {
    public Element a(Message paramMessage) throws com.intellij.licensecommon.f.c {
        if ((paramMessage instanceof com.intellij.licensecommon.message.impl.d)) {
            return a((com.intellij.licensecommon.message.impl.d) paramMessage);
        }
        if ((paramMessage instanceof com.intellij.licensecommon.message.impl.c)) {
            return a((com.intellij.licensecommon.message.impl.c) paramMessage);
        }
        throw new com.intellij.licensecommon.f.c("Unsupported data type: " + paramMessage.getClass());
    }

    private Element a(com.intellij.licensecommon.message.impl.d paramd) {
        String str;
        if (paramd.b() == 1) {
            str = "licenseUsed";
        } else {
            str = "U";
        }
        return a(new Element(str), paramd);
    }

    private Element a(com.intellij.licensecommon.message.impl.c paramc) {
        return a(new Element("licenseUnused"), paramc);
    }

    private Element a(Element paramElement, TaggedMessage parama) {
        int i = parama.b();
        if (i == 1) {
            str = parama.TaggedMessage();
            if (str == null) {
                return paramElement;
            }
            return paramElement.addContent(new Element("tag").setText(str));
        }
        String str = parama.TaggedMessage();
        if (str != null) {
            paramElement.setAttribute("i", str);
        }
        return paramElement.setAttribute("v", String.valueOf(i));
    }

    private Element a(Element paramElement, b paramb) {
        Element localElement;
        if (paramb.b() == 1) {
            localElement = a(paramb.getLicense());
        } else {
            localElement = b(paramb.getLicense());
        }
        return a(paramElement, paramb).addContent(localElement);
    }

    private Element a(LicenseImpl paramf) {
        if (paramf == null) {
            return new Element("license");
        }
        return new Element("license").addContent(new Element("name").addContent(paramf.getUsername())).addContent(new Element("key").addContent(paramf.getKey()));
    }

    private Element b(LicenseImpl paramf) {
        if (paramf == null) {
            return new Element("L");
        }
        return new Element("L").setAttribute("n", paramf.getUsername()).setAttribute("k", paramf.getKey());
    }
}
